unit hadeopfmanager;

{$mode objfpc}{$H+}

interface

uses
  Classes,
  SysUtils,
  hadebroker,
  hadevisitormanager,
  hadeconnectionmanager;

type
  THadeOIDStrategy = (oidGUID, oidAutoInc,oidUserDefined);
  { THadeOPFManager }
  THadeOPFManager = class
  private
    FOIDStrategy: THadeOIDStrategy;
    function getConnectionManager: THadeConnectionPool;
    function getVisitorManager: THadeVisitorManager;
  protected
    constructor Create;
  public
    property OIDStrategy: THadeOIDStrategy read FOIDStrategy write FOIDStrategy;
    property VisitorManager : THadeVisitorManager read getVisitorManager;
    property ConnectionManager : THadeConnectionPool read getConnectionManager;
    //Register the Connection
    procedure RegisterConnection(const AHdBroker: THdBroker;
      const AConName, ADatabase, AHost, AUser, APassword: string;
      const IsDefault: boolean = False);//<== default is false
  end;

function GHadeOPFManager: THadeOPFManager;

implementation
uses
  hadesqlvisitor;
var
  FHadeOPFManager: THadeOPFManager = nil;

function GHadeOPFManager: THadeOPFManager;
begin
  { TODO 2 -oFajar -cOPF : thread safe }
  if not Assigned(FHadeOPFManager) then
    FHadeOPFManager := THadeOPFManager.Create;
  Result := FHadeOPFManager;
end;

{ THadeOPFManager }

function THadeOPFManager.getVisitorManager: THadeVisitorManager;
begin
  Result := GHadeVisitorManager;
end;

function THadeOPFManager.getConnectionManager: THadeConnectionPool;
begin
  Result := GHadeConnectionManager;
end;

constructor THadeOPFManager.Create;
begin

end;

procedure THadeOPFManager.RegisterConnection(const AHdBroker: THdBroker;
  const AConName, ADatabase, AHost, AUser, APassword: string; const IsDefault: boolean);
begin
  GHadeConnectionManager.RegisterConnection(AConName,
    ADatabase,
    AHost,
    AUser,
    APassword,
    AHdBroker,
    IsDefault);
end;

initialization
  GHadeOPFManager();
finalization
  if Assigned(FHadeOPFManager) then
    FreeAndNil(FHadeOPFManager);

end.

